using System;
using UnityEngine;

namespace Core
{
    public class Collision2DListener : MonoBehaviour
    {
        public event Action<Collision2D> OnCollisionEnter;
        public event Action<Collision2D> OnCollisionExit;

        public static Collision2DListener Get(GameObject go)
        {
            return go.GetComponent<Collision2DListener>() ??
                   go.AddComponent<Collision2DListener>();
        }

        private void OnCollisionEnter2D(Collision2D col)
        {
            // Debug.Log($"OnCollisionEnter2D col: {col.gameObject.name}");

            OnCollisionEnter?.Invoke(col);
        }

        private void OnCollisionExit2D(Collision2D col)
        {
            // Debug.Log($"OnCollisionExit2D col: {col.gameObject.name}");

            OnCollisionExit?.Invoke(col);
        }

        // private void OnTriggerEnter2D(Collider2D other)
        // {
        //     Debug.Log($"OnTriggerEnter2D col: {other.gameObject.name}");
        //
        // }
        //
        // private void OnTriggerExit2D(Collider2D other)
        // {
        //     Debug.Log($"OnTriggerExit2D col: {other.gameObject.name}");
        //
        // }
    }
}